package com.cmf.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @Author: cmf
 * @Date: 2025/8/27 18:15
 * @Version: v1.0.0
 * @Description: 性别枚举，用于员工和地址簿
 **/
@Getter
public enum Gender {

    FEMALE(0, "女"),
    MALE(1, "男");

    // 枚举值
    @EnumValue
    // 序列化时返回给前端的值
    @JsonValue
    private final Integer gender;
    private final String desc;

    Gender(Integer gender, String desc) {
        this.gender = gender;
        this.desc = desc;
    }

    public static String getDescByGender(Integer gender) {
        for (Gender value : Gender.values()) {
            if (value.getGender().equals(gender)) {
                return value.getDesc();
            }
        }
        return null;
    }

    public static Gender getGenderByGender(Integer gender) {
        for (Gender value : Gender.values()) {
            if (value.getGender().equals(gender)) {
                return value;
            }
        }
        return null;
    }

    public static Integer getGenderByDesc(String desc) {
        for (Gender value : Gender.values()) {
            if (value.getDesc().equals(desc)) {
                return value.getGender();
            }
        }
        return null;
    }
}